package top.aiprogram.user.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import top.aiprogram.user.entity.User;
import top.aiprogram.user.service.UserService;
import javax.servlet.http.HttpSession;

/**
 * Created by HP on 2018/10/13.
 */
@Controller
@RequestMapping("user")
public class UserController  {
    @Autowired
    private UserService userService;
@RequestMapping("home")
    public String demo(){
        return "home";
    }
    /*
    @Author JackQi {www.coder520.com}
    @DATE 2018/10/16 19:58
    @Description:获取用户信息,返回给前端,配合前端设置的那个
    ajax进行使用,前端未发送任何数据.而是返回给前端一个json.
    */
    @RequestMapping("userinfo")
    @ResponseBody
    public User getuserinfo(HttpSession httpSession){
        User userinfo =(User) httpSession.getAttribute("userinfo");
        return userinfo;
    }

    /*
    @Author JackQi {www.coder520.com}
    @DATE 2018/10/16 21:38
    @Description:书写登出的方法
    */
    @RequestMapping("logout")
    public String logout(HttpSession httpSession){
        httpSession.invalidate();
        return "/login";
    }

}
